#include <QNetworkAccessManager>
#include <QCoreApplication>
#include "ConfigData.h"
#include "global.h"

bool isPressingShortcutWidget = false;

static QNetworkAccessManager *manager = nullptr;

QNetworkAccessManager *networkManagerInstance()
{
    if (manager == nullptr)
    {
        manager = new QNetworkAccessManager();
        int timeoutMs = ConfigData::instance().translate->networkTimeout->get();
        if (timeoutMs < 3000)
        {
            timeoutMs = 3000;
            ConfigData::instance().translate->networkTimeout->set(3000);
        }
        manager->setTransferTimeout(timeoutMs);

        QObject::connect(qApp, &QCoreApplication::aboutToQuit, qApp, []{
            delete manager;
            manager = nullptr;
        });
    }
    return manager;
}

